package com.woniuxy.goods.manaer.controller;

import com.github.pagehelper.PageInfo;
import com.netflix.discovery.converters.Auto;
import com.woniuxy.goods.manaer.feigns.GoodsFeignClient;
import com.woniuxy.goods.module.goods.Goods;
import com.woniuxy.goods.module.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class GoodsController {

    @Autowired
    GoodsFeignClient goodsFeignClient ;

    @GetMapping("/goods/list")
    public Result<PageInfo<Goods>> list(
            @RequestParam(value = "now",defaultValue = "1") Integer now,
            @RequestParam(value = "size",defaultValue = "2")Integer size,
            @RequestParam(value = "name",defaultValue = "") String name ,
            @RequestParam(value = "tid",defaultValue = "0")Integer tid){
        try {
            //发送远程调用查询商品信息
            PageInfo<Goods> pageInfo = goodsFeignClient.findGoodsByPage(now, size, name, tid);
            return Result.ok(pageInfo);
        }catch (RuntimeException e) {
            e.printStackTrace();
            return Result.fail();
        }
    }

    @PostMapping("/goods/add")
    public Result<Integer> add(@RequestBody Goods goods){
        try {
            //发送远程调用查询商品信息
            Integer num = goodsFeignClient.add(goods);
            return Result.ok(num);
        }catch (RuntimeException e) {
            e.printStackTrace();
            return Result.fail();
        }
    }

    @GetMapping("/wugd/ok")
    public String ok(String aaa){

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        return "蜗牛学院!!!"+aaa;
    }

    @GetMapping("/wugd/nok")
    public String woniu(String name,int age){


        return "蜗牛学院!!!"+name +"----"+age;
    }
}
